package com.benefm.multipar.pad.http;

import com.benefm.multipar.pad.AppConfig;
import com.benefm.multipar.pad.BaseApp;
import com.benefm.multipar.pad.model.HomeResult;
import com.benefm.multipar.pad.model.LoginInfo;
import com.benefm.multipar.pad.util.ACache;
import com.benefm.multipar.pad.util.AESUtil;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Callback;

public class HttpRequest {


    public static void login(String username, String password, Callback<HttpResult<LoginInfo>> callback) {
        try {
            password = AESUtil.Encrypt(password, AppConfig.AES_KEY);
        } catch (Exception e) {
            e.printStackTrace();
        }
        Map<String, String> map = new HashMap<>();
        map.put("username", username);
        map.put("password", password);
        map.put("appKey", AppConfig.APP_KEY);
        RetrofitClient
                .apiService()
                .login(map)
                .enqueue(callback);
    }

    public static void getDevices(int page, int size, Callback<HttpResult<HomeResult>> callback) {
        LoginInfo info = (LoginInfo) ACache.get(BaseApp.baseApp).getAsObject(AppConfig.LOGIN_INFO);
        if (info == null)
            return;
        Map<String, String> map = new HashMap<>();
        map.put("page", String.valueOf(page));
        map.put("size", String.valueOf(size));
        map.put("cid", info.cid);
        map.put("userId", info.username);
        map.put("fileType", "mss");
//        map.put("fileType", "testMss");
        RetrofitClient
                .apiService()
                .onlineDevices(map)
                .enqueue(callback);
    }

}
